// var a;
// console.log(a) // undefined
// console.log(b) // 报错 b is not defined

// function bar() {
//   var myName = 'bar1'
//   var test1 = 'bar2'
//   console.log(test)
// }

// function foo() {
//   var myName = 'foo1';
//   var test = 'bar2';
//   {
//     let test = 'foo3';
//     bar()
//   }
// }

// var test = 'global test'

// foo() // 'global test'

for (var i = 0; i <= 3; i++) {
  setTimeout(() => {
    console.log(i)
  }, 0);
} // 4444

var a = []
function Foo() {
  getName = function() {
    a.push('1')
  }
  return this
}

Foo.getName = function() {
  a.push('2')
}

Foo.prototype.getName = function() {
  a.push('3')
}

var getName = function() {
  a.push('4')
}

function getName() {
  a.push('5')
}

Foo.getName();
getName();
// Foo().getName();
getName();
new Foo.getName();
// new Foo().getName();
new new Foo().getName();

console.log(a)  // [2,4,4,2,3,3]

var foo = function(x) {
  return function(y) {
      return x + y
  }
}

foo(3)(4)       // 7


// 普通方法
var add = function(x, y) {
  return x + y;
}

console.log("柯里化函数结果：", add(3, 4))       //7 

var obj = new Proxy({}, {
  get: function (target, propKey, receiver) {
    console.log(`getting ${propKey}!`, obj);
    return Reflect.get(target, propKey, receiver);
  },
  set: function (target, propKey, value, receiver) {
    console.log(`setting ${propKey}!`, obj);
    return Reflect.set(target, propKey, value, receiver);
  }
});

obj.count = 1
++obj.count

console.log("最后的obj.count", obj)